﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aerthe.Model.Tasks
{
    public class MTask3
    {
        public List<ListsItem> ListTask = new List<ListsItem> { };
        //string BuforString;

        public MTask3()
        {
            using (var Base = new NorthwindEntities())
            {
                var query = Base.Products.Select(n => new
                {
                    Product = n,
                    Quant = n.Order_Details.Sum(m => m.Quantity)
                });

                var list = query.OrderByDescending(n => n.Quant);

                foreach (var a in list)
                {
                    this.ListTask.Add(new ListsItem(a.Product.ProductName, a.Quant.ToString()));
                }
            }
        }

        public void MViewConsole()
        {
            Console.WriteLine("|  {0,-35} |  {1}\n", "Product name", "Quantity");

            foreach (var a in this.ListTask)
            {
                Console.WriteLine("|  {0,-35} |  {1} szt.", a.Item1, a.Item2);
            }
        }
    }
}